hexagramData = {
	'111111': {
		'number': '1',
		'char': '乾',
		'name': 'qián',
		'translation': 'Force',
		'meaning': 'force, the creative, strong action, the key, and god'
	},
	'000000': {
		'number': '2',
		'char': '坤',
		'name': 'kūn',
		'translation': 'Field',
		'meaning': 'field, the receptive, acquiescence, and the flow'
	},
	'010001': {
		'number': '3',
		'char': '屯',
		'name': 'zhūn',
		'translation': 'Sprouting',
		'meaning': 'sprouting, difficulty at the beginning, gathering support, and hoarding'
	},
	'100010': {
		'number': '4',
		'char': '蒙',
		'name': 'méng',
		'translation': 'Enveloping',
		'meaning': 'enveloping, youthful folly, the young shoot, and discovering'
	},
	'010111': {
		'number': '5',
		'char': '需',
		'name': 'xū',
		'translation': 'Attending',
		'meaning': 'attending, waiting, moistened, and arriving'
	},
	'111010': {
		'number': '6',
		'char': '訟',
		'name': 'sòng',
		'translation': 'Arguing',
		'meaning': 'arguing, conflict, and lawsuit'
	},
	'000010': {
		'number': '7',
		'char': '師',
		'name': 'shī',
		'translation': 'Leading',
		'meaning': 'leading, the army, and the troops'
	},
	'010000': {
		'number': '8',
		'char': '比',
		'name': 'bǐ',
		'translation': 'Grouping',
		'meaning': 'grouping, holding together, and alliance'
	},
	'110111': {
		'number': '9',
		'char': '小畜',
		'name': 'xiǎo chù',
		'translation': 'Small Accumulating',
		'meaning': 'small accumulating, the taming power of the small, and small harvest'
	},
	'111011': {
		'number': '10',
		'char': '履',
		'name': 'lǚ',
		'translation': 'Treading',
		'meaning': 'treadin, strong passing over weak, and continuing'
	},
	'000111': {
		'number': '11',
		'char': '泰',
		'name': 'tài',
		'translation': 'Pervading',
		'meaning': 'pervading, peace, and greatness'
	},
	'111000': {
		'number': '12',
		'char': '否',
		'name': 'pǐ',
		'translation': 'Obstruction',
		'meaning': 'obstruction, standstill, stagnation, and selfish persons'
	},
	'111101': {
		'number': '13',
		'char': '同人',
		'name': 'tóng rén',
		'translation': 'Concording People',
		'meaning': 'concording people, fellowship with men, and gathering men'
	},
	'101111': {
		'number': '14',
		'char': '大有',
		'name': 'dà yǒu',
		'translation': 'Great Possessing',
		'meaning': 'great possessing, possessing in great measure, and the great possessing'
	},
	'000100': {
		'number': '15',
		'char': '謙',
		'name': 'qiān',
		'translation': 'Humbling',
		'meaning': 'humbling, modesty, and lifting up through modesty'
	},
	'001000': {
		'number': '16',
		'char': '豫',
		'name': 'yù',
		'translation': 'Providing For',
		'meaning': 'providing for, enthusiasm, and success'
	},
	'011001': {
		'number': '17',
		'char': '隨',
		'name': 'suí',
		'translation': 'Following',
		'meaning': 'following, perservering, yielding to, and serving'
	},
	'100110': {
		'number': '18',
		'char': '蠱',
		'name': 'gŭ',
		'translation': 'Correcting',
		'meaning': 'correcting, work on what has been spoiled, spoiling, decaying, and branch'
	},
	'000011': {
		'number': '19',
		'char': '臨',
		'name': 'lín',
		'translation': 'Nearing',
		'meaning': 'nearing, approach, and the forest'
	},
	'110000': {
		'number': '20',
		'char': '觀',
		'name': 'guān',
		'translation': 'Viewing',
		'meaning': 'viewing, contemplation, and looking up'
	},
	'101001': {
		'number': '21',
		'char': '噬嗑',
		'name': 'shì kè',
		'translation': 'Gnawing Bite',
		'meaning': 'gnawing bite, biting through, and biting and chewing'
	},
	'100101': {
		'number': '22',
		'char': '賁',
		'name': 'bì',
		'translation': 'Adorning',
		'meaning': 'adorning, grace, and luxuriance'
	},
	'100000': {
		'number': '23',
		'char': '剝',
		'name': 'bō',
		'translation': 'Stripping',
		'meaning': 'stripping, splitting apart, and flaying'
	},
	'000001': {
		'number': '24',
		'char': '復',
		'name': 'fù',
		'translation': 'Returning',
		'meaning': 'returning, the turning point, and cycling'
	},
	'111001': {
		'number': '25',
		'char': '無妄',
		'name': 'wú wàng',
		'translation': 'Without Embroiling',
		'meaning': 'without embroiling, innocence, the unexpected, and pestilence'
	},
	'100111': {
		'number': '26',
		'char': '大畜',
		'name': 'dà chù',
		'translation': 'Great Accumulating',
		'meaning': 'great accumulating, the taming power of the great, great storage, and potential energy'
	},
	'100001': {
		'number': '27',
		'char': '頤',
		'name': 'yí',
		'translation': 'Swallowing',
		'meaning': 'swallowing, providing nourishment, jaws, comfort, and security'
	},
	'011110': {
		'number': '28',
		'char': '大過',
		'name': 'dà guò',
		'translation': 'Great Exceeding',
		'meaning': 'great exceeding, preponderance of the great, great surpassing, and critical mass'
	},
	'010010': {
		'number': '29',
		'char': '坎',
		'name': 'kǎn',
		'translation': 'Gorge',
		'meaning': 'gorge, the abyss, and repeated entrapment'
	},
	'101101': {
		'number': '30',
		'char': '離',
		'name': 'lí',
		'translation': 'Radiance',
		'meaning': 'radiance, the clinging, fire, and the net'
	},
	'011100': {
		'number': '31',
		'char': '咸',
		'name': 'xián',
		'translation': 'Conjoining',
		'meaning': 'conjoining, influence, wooing, and feelings'
	},
	'001110': {
		'number': '32',
		'char': '恆',
		'name': 'héng',
		'translation': 'Persevering',
		'meaning': 'persevering, duration, and constancy'
	},
	'111100': {
		'number': '33',
		'char': '遯',
		'name': 'dùn',
		'translation': 'Retiring',
		'meaning': 'retiring, retreat, and yielding'
	},
	'001111': {
		'number': '34',
		'char': '大壯',
		'name': 'dà zhuàng',
		'translation': 'Great Invigorating',
		'meaning': 'great invigorating, the power of the great, and great maturity'
	},
	'101000': {
		'number': '35',
		'char': '晉',
		'name': 'jìn',
		'translation': 'Prospering',
		'meaning': 'prospering, progress, and waters'
	},
	'000101': {
		'number': '36',
		'char': '明夷',
		'name': 'míng yí',
		'translation': 'Darkening of the Light',
		'meaning': 'darkening of the light, brilliance injured, and intelligence hidden'
	},
	'110101': {
		'number': '37',
		'char': '家人',
		'name': 'jiā rén',
		'translation': 'Dwelling People',
		'meaning': 'dwelling people, the family, the clan, and family members'
	},
	'101011': {
		'number': '38',
		'char': '睽',
		'name': 'kuí',
		'translation': 'Polarising',
		'meaning': 'polarising, opposition, and perversion'
	},
	'010100': {
		'number': '39',
		'char': '蹇',
		'name': 'jiǎn',
		'translation': 'Limping',
		'meaning': 'limping, obstruction, and afoot'
	},
	'001010': {
		'number': '40',
		'char': '解',
		'name': 'xiè',
		'translation': 'Taking Apart',
		'meaning': 'taking apart, deliverance, and untangled'
	},
	'100011': {
		'number': '41',
		'char': '損',
		'name': 'sǔn',
		'translation': 'Diminishing',
		'meaning': 'diminishing, decrease, and shift in wealth'
	},
	'110001': {
		'number': '42',
		'char': '益',
		'name': 'yì',
		'translation': 'Augmenting',
		'meaning': 'augmenting, increase, and sacrifice of the higher to help the lower'
	},
	'011111': {
		'number': '43',
		'char': '夬',
		'name': 'guài',
		'translation': 'Displacement',
		'meaning': 'displacement, resoluteness, and break through'
	},
	'111110': {
		'number': '44',
		'char': '姤',
		'name': 'gòu',
		'translation': 'Coupling',
		'meaning': 'coupling, coming to meet, and meeting'
	},
	'011000': {
		'number': '45',
		'char': '萃',
		'name': 'cuì',
		'translation': 'Clustering',
		'meaning': 'clustering, gathering together, amassing, and finished'
	},
	'000110': {
		'number': '46',
		'char': '升',
		'name': 'shēng',
		'translation': 'Ascending',
		'meaning': 'ascending, pushing upward, and progress requiring effort'
	},
	'011010': {
		'number': '47',
		'char': '困',
		'name': 'kùn',
		'translation': 'Confining',
		'meaning': 'confining, exhaustion, and entangled'
	},
	'010110': {
		'number': '48',
		'char': '井',
		'name': 'jǐng',
		'translation': 'Welling',
		'meaning': 'welling, the well, and from the foundations'
	},
	'011101': {
		'number': '49',
		'char': '革',
		'name': 'gé',
		'translation': 'Skinning',
		'meaning': 'skinning, revolution, molting, the bridle'
	},
	'101110': {
		'number': '50',
		'char': '鼎',
		'name': 'dǐng',
		'translation': 'Holding',
		'meaning': 'holding, the cauldron, and fostering able men'
	},
	'001001': {
		'number': '51',
		'char': '震',
		'name': 'zhèn',
		'translation': 'Shake',
		'meaning': 'shake, the arousing, shock, and thunder'
	},
	'100100': {
		'number': '52',
		'char': '艮',
		'name': 'gèn',
		'translation': 'Bound',
		'meaning': 'bound, keeping still, and stilling'
	},
	'110100': {
		'number': '53',
		'char': '漸',
		'name': 'jiàn',
		'translation': 'Infiltrating',
		'meaning': 'infiltrating, development, gradual process, and advancement'
	},
	'001011': {
		'number': '54',
		'char': '歸妹',
		'name': 'guī mèi',
		'translation': 'Converting the Maiden',
		'meaning': 'converting the maiden, the marrying maiden, and returning maiden'
	},
	'001101': {
		'number': '55',
		'char': '豐',
		'name': 'fēng',
		'translation': 'Abounding',
		'meaning': 'abounding, abundance, and fullness'
	},
	'101100': {
		'number': '56',
		'char': '旅',
		'name': 'lǚ',
		'translation': 'Sojourning',
		'meaning': 'sojourning, the wanderer, and traveling'
	},
	'110110': {
		'number': '57',
		'char': '巽',
		'name': 'xùn',
		'translation': 'Ground',
		'meaning': 'ground, the gentle, the penetrating, wind, and calculations'
	},
	'011011': {
		'number': '58',
		'char': '兌',
		'name': 'duì',
		'translation': 'Open',
		'meaning': 'open, the joyous, lake, usurpation'
	},
	'110010': {
		'number': '59',
		'char': '渙',
		'name': 'huàn',
		'translation': 'Dispersing',
		'meaning': 'dispersing, dissolution, and dispersal'
	},
	'010011': {
		'number': '60',
		'char': '節',
		'name': 'jié',
		'translation': 'Articulating',
		'meaning': 'articulating, limitation, and moderation'
	},
	'110011': {
		'number': '61',
		'char': '中孚',
		'name': 'zhōng fú',
		'translation': 'Center Returning',
		'meaning': 'center returning, inner truth, and central return'
	},
	'001100': {
		'number': '62',
		'char': '小過',
		'name': 'xiǎo guò',
		'translation': 'Small Exceeding',
		'meaning': 'small exceeding, preponderance of the small, and small surpassing'
	},
	'010101': {
		'number': '63',
		'char': '既濟',
		'name': 'jì jì',
		'translation': 'Already Fording',
		'meaning': 'already fording, after completion, and already completed or done'
	},
	'101010': {
		'number': '64',
		'char': '未濟',
		'name': 'wèi jì',
		'translation': 'Not Yet Fording',
		'meaning': 'not yet fording, before completion, and not yet completed or done'
	}
};

function OracleAssistant(argFromPusher) {
}

OracleAssistant.prototype = {
	setup: function() {
		Ares.setupSceneAssistant(this);
	},
	activate: function() {
		//calculate symbols
		var symbols = [];
		var totalProb = oldYangProb + oldYinProb + youngYangProb + youngYinProb;
		var i;
		for (i = 0; i < oldYangProb; i++)
		{
			symbols.push('old-yang');
		}
		for (i = 0; i < oldYinProb; i++)
		{
			symbols.push('old-yin');
		}
		for (i = 0; i < youngYangProb; i++)
		{
			symbols.push('young-yang');
		}
		for (i = 0; i < youngYinProb; i++)
		{
			symbols.push('young-yin');
		}
		
		var firstSymbol = [];
		var secondSymbol = [];
		
		for (i = 0; i < 6; i++)
		{
			var randomIndex = Math.floor(Math.random() * totalProb);
			//Mojo.Log.info(randomIndex);
			firstSymbol.push(symbols[randomIndex]);
			secondSymbol.push(this.changeSymbol(firstSymbol[i]));
		}
		var firstSymbolBinary = this.binarySymbol(firstSymbol);
		var secondSymbolBinary = this.binarySymbol(secondSymbol);
		
		//display symbols and meaning from yi jing
		var report = "";
		
		var generateTable = function(symbol, symbolBinary)
		{
			var table = '<table>';
			var tdWidth = 30;
			var tdMiddleWidth = 10;
			var tdTotalWidth = 2*tdWidth + tdMiddleWidth;
			var trHeight = 10;
			var trSpacing = 5;
			var oldStyle = "background-color: gray;";
			var youngStyle = "background-color: black;";
			for (var i = 0; i < 6; i++)
			{
				var outsideStyle;
				var split;
				//Mojo.Log.info(symbol[i] + " - " + i);
				switch (symbol[i])
				{
					case 'old-yang':
						outsideStyle = oldStyle;
						split = false;
						break;
					case 'old-yin':
						outsideStyle = oldStyle;
						split = true;
						break;
					case 'young-yang':
						outsideStyle = youngStyle;
						split = false;
						break;
					case 'young-yin':
						outsideStyle = youngStyle;
						split = true;
						break;
					default:
						//Mojo.Log.info(symbol[i] + " - " + i);
						outsideStyle = 'background-color: red;';
						split = false;
						break;
				}
				table += '<tr height="' + trHeight + '">';
				if (split) {
					table += '<td width="' + tdWidth + '" style="' + outsideStyle + '"></td>';
					table += '<td width="' + tdMiddleWidth + '"></td>';
					table += '<td width="' + tdWidth + '" style="' + outsideStyle + '"></td>';
				}
				else {
					table += '<td colspan="3" width="' + tdTotalWidth + '" style="' + outsideStyle + '"></td>';
				}
				table += '</tr>';
				table += '<tr height="' + trSpacing + '"><td colspan="3"></td></tr>';
			}
			table += '<tr><td colspan="3" align="center">' + hexagramData[symbolBinary]['number'] + '</td></tr>';
			//table += '<tr><td colspan="3" align="center">(' + hexagramData[symbolBinary]['name'] + ')</td></tr>';
			//table += '<tr><td colspan="3" align="center">' + hexagramData[symbolBinary]['translation'] + '</td></tr>';
			table += "</table>";
			return table;
		};
		
		report += '<table align="center"><tr><td align="center" valign="top">';
		report += generateTable(firstSymbol, firstSymbolBinary);
		report += '</td><td align="center" width="50">&rArr;</td><td align="center" valign="top">';
		report += generateTable(secondSymbol, secondSymbolBinary);
		report += "</td></tr></table>";
		
		//report += '<h3 align="center">Interpretation</h3>';
		report += '<p>Hexagram ' + hexagramData[firstSymbolBinary]['number'];
		report += ' (' + hexagramData[firstSymbolBinary]['char'];
		report += ', ' + hexagramData[firstSymbolBinary]['name'];
		report += ', ' + hexagramData[firstSymbolBinary]['translation'];
		report += ') meaning ' + hexagramData[firstSymbolBinary]['meaning'];
		report += '; changing into Hexagram ' + hexagramData[secondSymbolBinary]['number'];
		report += ' (' + hexagramData[secondSymbolBinary]['char'];
		report += ', ' + hexagramData[secondSymbolBinary]['name'];
		report += ', ' + hexagramData[secondSymbolBinary]['translation'];
		report += '), meaning ' + hexagramData[secondSymbolBinary]['meaning'];
		report += '.</p>';
		
		this.controller.get("oracleResponseHtml").innerHTML = report;
	},
	cleanup: function() {
		Ares.cleanupSceneAssistant(this);
	},
	changeSymbol: function(symbol) {
		switch(symbol) {
			case 'old-yang':
				return 'old-yin';
			case 'old-yin':
				return 'old-yang';
			default:
				return symbol;
		}
	},
	binarySymbol: function(symbol) {
		binary = "";
		for (var i = 0; i < 6; i++)
		{
			if (symbol[i] == 'old-yang' || symbol[i] == 'young-yang')
			{
				binary += "1";
			}
			else
			{
				binary += "0";
			}
		}
		return binary;
	}
};